#!/usr/bin/perl
use strict;
use warnings;
use autodie;

use Encode(qw(decode));

use Spreadsheet::WriteExcel;

if ($#ARGV == -1 || $#ARGV == 0) {
	die "$0 in.txt ... out.xls.\n";
}

my $tools_path = $ENV{'tools_path'};
my $lib = $tools_path . '/perl_module/Spreadsheet-WriteExcel-2.40/lib';
push (@INC, $lib);


my $out_file = $ARGV[$#ARGV];
my $workbook  = Spreadsheet::WriteExcel -> new($out_file);

my @sheets= $ARGV[0..($#ARGV-1)];


my ($worksheet, $file_name, $row);
foreach my $i (0..($#ARGV-1)) {
	$worksheet = $workbook->add_worksheet($sheets[$i]);
	$file_name = $ARGV[$i];
	open (CVS, $file_name) or die "$!";
	
	$row = 0;
	while (<CVS>) {
        chomp;
        my @Fld = split('\t', $_);
        my $col = 0;
        foreach my $token (@Fld) {
                $worksheet->write_string($row, $col, decode('gb2312',$token));
                $col++;
        }
        $row++;
	}

}

$workbook->close();


exit 0;

